/**
 * Copyright (c) 2005-2012 https://github.com/zhangkaitao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.monkey.core.web.jcaptcha;

import com.monkey.core.web.response.MonkeyResponseDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * jcaptcha 验证码验证
 */
@Controller
@RequestMapping("/jcaptcha-validate")
public class JCaptchaValidate {

    @RequestMapping(method = RequestMethod.GET)
    public MonkeyResponseDto jqueryValidationEngineValidate(HttpServletRequest request, @RequestParam String code) {
        MonkeyResponseDto responseDto = new MonkeyResponseDto();

        if (!JCaptcha.hasCaptcha(request, code)) {
            responseDto.fail("验证码校验失败");
        } else {
            responseDto.success("验证码校验成功");
        }

        return responseDto;
    }
}
